let request = require('../../../../utils/request.js')

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    shopList: {},
    isShopkeeper:null,
  },

  lifetimes: {
    attached: function() {
      console.log('在组件实例进入页面节点树时执行')
      this.setData({
        isShopkeeper:wx.getStorageSync('isShopkeeper') //0 否   1是  店主
      })
      //  获取商户列表
      this.getShopList()
    },
    detached: function() {
      console.log('在组件实例被从页面节点树移除时执行')
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
      /**
     * 获取管理员列表
     */
    getShopList() {
      request.http(
        '/shop/shop-info/get-shop-info-list', 'GET', { shopId: wx.getStorageSync('shopId')}
      ).then(res => {
        let data = res.data
        if (data.code == 200) {
          this.setData({ shopList: data.data })
        }
      })
    },
    // 删除管理员
    delManager(e) {
      let _this = this
      wx.showModal({
        title: '操作确认',
        content: '是否确认删除管理员？',
        success(res) {
          if (res.confirm) {
            request.http(
              '/shop/shop-manager/delete', 
              'POST', 
              {id: e.currentTarget.dataset.id}
            ).then(res => {
              let data = res.data
              if (data.code == 200) {
                wx.showToast({ title: '删除成功' })
                _this.getShopList()
              }
            })
          }
        }
      })
    },
    // 跳转编辑管理员页面
    toSetManager(e) {
      wx.navigateTo({ url: e.target.dataset.url })
    },
    /**
     * 打开拨号弹窗
     */
    showCallPhoneDialog(e) {
      this.triggerEvent('showCallPhoneDialog', e.target.dataset.phone)
    },
  }
})
